#!/bin/bash
#zhushi:Linux 系统信息获取
#Author_Name=Weiyi
clear
if [ $# -eq 0 ];then    # "$#" 提取位置参数的个数
reset_terminal=$(tput sgr0)  #设置高亮输出
#Check OS Type (系统类型)
	os=$(uname -o)
	echo -e '\E[32m' "OS Type (系统类型):" $reset_terminal $os
#Check OS Release Version and Name (系统发行版本及名字)
	os_Rv=$(lsb_release -a | grep "Description" |awk '{print $2 " " $3 " " $4 " "$5$6 }')
	echo -e '\E[32m' "OS Release Version and Name (系统发行版本及名字):" $reset_terminal $os_Rv
#Check Architecture (系统Cpu 386 还是 X64架构)
	os_Ar=$(uname -m)
	echo -e '\E[32m' "Architecture (系统Cpu 386 还是 X64架构):" $reset_terminal $os_Ar
#Check Kernel Release (内核版本)
	os_Kr=$(uname -r)
	echo -e '\E[32m' "Kernel Release (内核版本)" $reset_terminal $os_Kr
#Check hostname
	os_hostname=$(echo $HOSTNAME)
	echo -e '\E[32m' "OS Hostname (主机名):" $reset_terminal $os_hostname
#Check Internal IP (内部IP)
	os_InIP=$(hostname -I)
	echo -e '\E[32m' "Internal IP (内部IP):" $reset_terminal $os_InIP
#Check External IP (外部IP)
	os_ExIP=$(curl -s http://ipecho.net/plain)
	echo -e '\E[32m' "External IP (外部IP):" $reset_terminal $os_ExIP
#Check DNS
	os_Dns=$(cat /etc/resolv.conf |grep -E "\<nameserver[ ]+" |awk '{print $NF}')
	# "\<nameserver[ ]+" 表示匹配以nameserver开头的多个[ ]+ //空格
	# "$NF" 默认以空格为分割符打印他得最后一行
	echo -e '\E[32m' "OS DNS (系统DNS):" $reset_terminal $os_Dns
#Check IF Connected To Internet or not (是否能连接英特网)
	ping -c 2 www.baidu.com &>/dev/null && echo "Internet:Connected(正常通信)" || echo "Internet:Disconnected(不能正常通信)" 
#Check logged In Users (当前登陆的用户)
	who >/tmp/who
	echo -e '\E[32m' "Logged In Users (当前登陆的用户)" $reset_terminal && cat /tmp/who
	rm -rf /tmp/who
#Check Proc Information
echo -e '\E[35m]' "############################# Proc info (内存使用信息) ##########################################\n"
	system_mem_usages=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}END{print (total-free)/1024}' /proc/meminfo)
	echo -e '\E[32m' "System Mem Usages (当前系统使用内存信息-MB):" $reset_terminal $system_mem_usages
	application_mem_usages=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}/^Cached/{cached=$2}/Buffers/{buffers=$2}END{print (total-free-cached-buffers)/1024}' /proc/meminfo)
	echo -e '\E[32m' "Application Mem Usages (当前应用使用内存信息-MB):" $reset_terminal $application_mem_usages
#Check Cpu Information >> load average后面分别是1分钟、5分钟、15分钟的负载情况
echo -e '\E[35m]' "############################# Cpu load info (Cpu负载信息) ##########################################\n"
	load_average=$(top -n 1 -b |grep "load average:" |awk '{print $10 $11 $12}')
	echo -e '\E[32m' "Cpu load info (Cpu负载信息):" $reset_terminal $load_average
#Check Disk Information
echo -e '\E[35m]' "############################# Disk info (磁盘使用信息) ##########################################\n"
	disk_info=$(df -h |grep -vE "Filesytem|tmpfs" |awk '{printf $1 "\t" $5 "\n"}')
	# -p 使用输出更紧凑
	echo -e '\E[32m' "Disk Usages (磁盘使用信息):" $reset_terminal $disk_info
fi
